package com.yuwen.yuwenRPC.protocol;


/**
 * 协议消息状态枚举类
 */
public enum ProtocolMessageStatusEnum {
    OK("ok",200),
    BAD_REQUEST("bad request",40),
    BAD_RESPONSE("bad response",50),
    ;

    private final String text;
    private final int value;

    ProtocolMessageStatusEnum(String text, int value) {
        this.text = text;
        this.value = value;
    }

    /**
     * 通过 value (响应码) 得到message
     * @param value 响应码
     * @return message
     */
    public static ProtocolMessageStatusEnum getEnumByValue(int value) {
        for (ProtocolMessageStatusEnum e : ProtocolMessageStatusEnum.values()) {
            if (e.value == value) {
                return e;
            }
        }
        return null;
    }

    public String getText() {
        return text;
    }

    public int getValue() {
        return value;
    }
}
